

alter  trigger tft_msfixedassets_bi on dbo.tft_msfixedassets
instead of insert
as 
begin
  set nocount on
  declare @fixedassetid int;
  declare @nyear int;
  declare @nmonth int;
  declare @filid int;
  declare @itemno int;
  declare @bmsrcamt decimal(18,2)
  declare @tmincsrcamt decimal(18,2) 
  declare @tmdecsrcamt decimal(18,2)
  declare @deprrate decimal(18,2)
  declare @sumdprmonth decimal(18,2)
  declare @tmincdpramt decimal(18,2)
  declare @tmdecdpramt decimal(18,2)
  declare @ydpramt decimal(18,2)
  declare @tmdpramt decimal(18,2)
  declare @bmdpramt decimal(18,2)
  declare @needfresh int;

  declare cur_tft cursor for select fixedassetid,nyear,nmonth,filid,
    bmsrcamt,tmincsrcamt,tmdecsrcamt,deprrate,sumdprmonth,
    tmincdpramt,tmdecdpramt,ydpramt,tmdpramt,bmdpramt,needfresh
    from Inserted 
  open cur_tft 
  fetch next from cur_tft into @fixedassetid, @nyear, @nmonth, @filid,
    @bmsrcamt, @tmincsrcamt, @tmdecsrcamt, @deprrate, @sumdprmonth,
    @tmincdpramt, @tmdecdpramt, @ydpramt, @tmdpramt, @bmdpramt, @needfresh
  while @@fetch_status = 0 
  begin
    if @filid is null
      select @filid=filid from tfb_fixedassets where fixedassetid=@fixedassetid
    Select @bmsrcamt=isnull(@bmsrcamt,0),@tmincsrcamt = isnull(@tmincsrcamt,0)
      ,@tmdecsrcamt = isnull(@tmdecsrcamt,0), @deprrate = isnull(@deprrate,0)
      ,@sumdprmonth = isnull(@sumdprmonth,0), @tmincdpramt = isnull(@tmincdpramt,0)
      ,@tmdecdpramt = isnull(@tmdecdpramt,0), @ydpramt = isnull(@ydpramt,0)
      ,@tmdpramt = isnull(@tmdpramt ,0), @bmdpramt = isnull(@bmdpramt ,0),@needfresh = isnull(@needfresh ,0)    

    insert into tft_msfixedassets(fixedassetid, nyear, nmonth, filid, bmsrcamt,
      tmincsrcamt, tmdecsrcamt, deprrate, sumdprmonth,
      tmincdpramt, tmdecdpramt, ydpramt, tmdpramt, bmdpramt, needfresh) 
      values(@fixedassetid, @nyear, @nmonth, @filid, @bmsrcamt, 
      @tmincsrcamt, @tmdecsrcamt, @deprrate, @sumdprmonth,
      @tmincdpramt, @tmdecdpramt, @ydpramt, @tmdpramt, @bmdpramt, @needfresh)
    fetch next from cur_tft into @fixedassetid, @nyear, @nmonth, @filid,
      @bmsrcamt, @tmincsrcamt, @tmdecsrcamt, @deprrate, @sumdprmonth,
      @tmincdpramt, @tmdecdpramt, @ydpramt, @tmdpramt, @bmdpramt, @needfresh
   end
  close cur_tft 
  deallocate cur_tft          
end




